package in.muton.edushare.common;

import in.muton.edushare.wicket.models.CayenneList;

import java.util.List;

import org.apache.wicket.model.IModel;

import com.edushare.common.util.StringUtil;
import com.edushare.common.vo.Users;

public class UserFilter {
	public static CayenneList<Users> filterByString(CayenneList<Users> in, String filterString){
		if(!StringUtil.isValid(filterString)){
			return in;
		}
		List<IModel<Users>> userList = in.getObject();
		CayenneList<Users> newList = new CayenneList<Users>(null);
		for(IModel<Users> u:userList){
			if(u.getObject().getCompleteUserName().toLowerCase().contains(filterString.toLowerCase())){
				newList.add(u.getObject());
			}else if(u.getObject().getUserName().toLowerCase().contains(filterString.toLowerCase().trim())){
				newList.add(u.getObject());
			}else if(u.getObject().getEmail().toLowerCase().contains(filterString.toLowerCase().trim())){
				newList.add(u.getObject());
			}
		}
		return newList;
	}
}
